package com.bstek.xxlJob.jobhandler;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @Title: xxl-job例子
 * @Package: com.bstek.xxlJob.config
 * @Description:
 * @Author: zxq
 * @Date: 2023/12/1 - 14:28
 */

@Component
public class SampleXxlJob {
    private static Logger logger = LoggerFactory.getLogger(SampleXxlJob.class);

    @XxlJob("xxlJobHandler1")
    public void xxlJobHandler1() throws InterruptedException {
        logger.info("开始执行xxlJob任务了.........");
        XxlJobHelper.log("XXL-JOB, Hello World.");
        for (int i = 0; i < 5; i++) {
            XxlJobHelper.log("beat at:" + i);
            TimeUnit.SECONDS.sleep(2);
        }
    }
    @XxlJob(value = "xxlJobHandler2",init = "init",destroy = "destroy")
    public ReturnT<String> execute(String param){
        logger.info("开始执行定时任务......");
        XxlJobHelper.log("task.....");
        return ReturnT.SUCCESS;

    }

    private void init(){
        logger.info("初始化方法..............");
    }

    private void destroy(){
        logger.info("销毁方法..............");

    }

}
